package com.atguigu.crowd.mvc.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atguigu.crowd.entity.Project;
import com.atguigu.crowd.entity.vo.OrderVO;
import com.atguigu.crowd.service.api.OrderService;
import com.atguigu.crowd.util.ResultEntity;
import com.github.pagehelper.PageInfo;

@Controller
public class OrderHandler {

	@Autowired
	private OrderService orderService;
	
	
	//查看订单详情
	@ResponseBody
	@RequestMapping("/order/look.json")
	public ResultEntity<OrderVO> getProject(@RequestParam("orderId") Integer orderId){
		
		OrderVO order = orderService.getOrderDetail(orderId);
		return ResultEntity.successWithData(order);
	}

	//分页显示项目受检列表
	@ResponseBody 
	@RequestMapping("/order/get/page/info.json")
	public ResultEntity<PageInfo<OrderVO>> getPageInfo(
				@RequestParam(value="pageNum", defaultValue="1") Integer pageNum,
				@RequestParam(value="pageSize", defaultValue="5") Integer pageSize,
				@RequestParam(value="keyword", defaultValue="") String keyword
			) {
		
		// 调用Service方法获取分页数据
		PageInfo<OrderVO> pageInfo = orderService.getPageInfo(pageNum, pageSize, keyword);
		// 封装到ResultEntity对象中返回（如果上面的操作抛出异常，交给异常映射机制处理）
		return ResultEntity.successWithData(pageInfo);
	}
}
